<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<div th:replace="XAdmin/commons/header"></div>
<link rel="stylesheet" th:href="@{/XAdmin/css/login.css}">
<body class="login-bg">
<div id="app" class="login layui-anim layui-anim-up">
    <div class="message">朔西湖预定系统</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form">
        <input name="userName" placeholder="用户名" v-model="userName" type="text" lay-verify="required"
               class="layui-input">
        <hr class="hr15">
        <input name="pwd" lay-verify="required" placeholder="密码" v-model="pwd" type="password" class="layui-input">
        <hr class="hr15">
        <input value="登录" lay-submit lay-filter="login" type="submit"
               @click.prevent="login">
        <hr class="hr20">
    </form>
</div>
<script>

    const vm = new Vue({
        el: "#app",
        data: {
            userName: null,
            pwd: null
        },
        methods: {
            login() {

                let request = {
                    url: "admin/toLogin",
                    method: "post",
                    data: JSON.stringify({
                        username: this.userName,
                        pwd: this.pwd
                    })
                };
                sendRequest(request, (res) => {
                    if (res.code === 20000) {
                        localStorage.setItem("token", res.data.token);
                        localStorage.setItem("userInfo", JSON.stringify(res.data.userInfo));
                        localStorage.setItem("userId", JSON.stringify(res.data.userInfo.id));
                        localStorage.setItem("menuDTOList", JSON.stringify(res.data.menuDTOList));
                        setTimeout(function () {
                            window.location.href = $projectName;
                        }, 100)
                    } else {
                        layer.msg(res.msg, {
                            icon: 5
                        });
                    }

                });
            }
        }
    });
</script>
</body>
</html>